﻿using UnityEngine;
using System.Collections;

public class player : MonoBehaviour 
{
	public float up;
	public float down;
	public float left;
	public float right;
	//public GameObject black;
	public int life;


	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		transform.Translate(0, up * Time.deltaTime, 0);
		if(Input.GetKey(KeyCode.A))
		{
			transform.Translate(left * Time.deltaTime, 0, 0);

			

		}
		if(Input.GetKey(KeyCode.D))
		{
			transform.Translate(right * Time.deltaTime, 0, 0);
			
		}

		if(Input.GetKey(KeyCode.W))
		{
			transform.Translate(0, right * Time.deltaTime, 0);
			
		}

		if(Input.GetKey(KeyCode.S))
		{
			transform.Translate(0, down * Time.deltaTime, 0);
			//transform.Translate.tag == "MainCamera"(0, down * Time.deltaTime, 0);
			
		}

		if(transform.position.y < -23)
		{
			down = 0;
		}
		else
		{
			down = -3;
		}



		/*if(Camera.main.position.y > 11)
		{
			//transform.Translate(0, velocity * Time.deltaTime, 0);
			transform.Translate(0 , Camera.main.position.y + scene.position.y, 0);

		}*/

		if(transform.position.y > 19)
		{
			transform.position = new Vector3(transform.position.x, -19, transform.position.z);

		}

		if(transform.position.x < -4)
		{
			transform.position = new Vector3( -4 , transform.position.y, transform.position.z);

		}

		if(transform.position.x > 3)
		{
			transform.position = new Vector3( 3 , transform.position.y, transform.position.z);
			
		}

		if(life == 0)
		{
			Application.LoadLevel("GameOver");
		}

		/*if(GetComponent<goup_black>().posicao_continua.y <= transform.position.y - 9)
		{
			Debug.Log("oiiujijiu");

		}*/

	}

	/*void OnCollisionEnter2D(Collision2D coll)
	{
		Debug.Log("oioi");
		//if(coll.GameObject.tag)
		//{
		//coll.GameObject.SendMessage("ApplyDamage", 10);
		
		//}
	}*/ 

	void OnGUI()
	{ 
		GUI.Label(new Rect(10,10, 100, 50), "öi" + life);

	}

	void OnTriggerEnter2D(Collider2D coll)
	{

		if(coll.gameObject.tag == "black")
		{
			life --;
		}



	}
}
	